﻿
namespace Mulala.Cavan.Presentation.Mvc.Controller
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Mulala.Cavan.Presentation.Seedwork;
    using Mulala.Cavan.Domain.MainBoundedContext.InformationModule;
    using Mulala.Cavan.Domain.MainBoundedContext.SearchModule;
    using Mulala.Cavan.Presentation.Mvc.ViewModel;
    using Mulala.Cavan.Application.MainBoundedContext.InformationModule;
    using System.Web.Mvc;
    using Mulala.Cavan.Domain.MainBoundedContext.Setting;

    public class UserMessageController : EntityController<UserMessage, UserMessageSearch, IUserMessageViewModel, IUserMessageAppService>, IUserMessageController
    {
        public override string ControllerName
        {
            get { return ControllerConst.USERMESSAGE; }
        }

        public override bool UseDenied
        {
            get { return false; }
        }

        public UserMessageController()
        {
            this.Model = ModelFactory.CreateModel<IUserMessageViewModel>();
        }

        [ActionName("messsages")]
        [ChildActionOnly]
        public ActionResult GetUserMessages(int ownerID, int cp)
        {
            IUserMessagesViewModel userMessagesViewModel = ModelFactory.CreateModel<IUserMessagesViewModel>();

            IDictionary<string, bool> orderBy = new Dictionary<string, bool>();
            orderBy.Add("CreateTime", true);
            UserMessageSearch search = UserMessageSearchFactory.CreateUserMessageSearch(ownerID, orderBy, cp, Project.Settings.MaxRowsPerPage);
            long total = 0;
            IList<UserMessage> userMessages = this.AppService.GetBySearch(search, out total).ToList();
            userMessagesViewModel.UserMessages = UserMessageViewModelConverter.Convert(userMessages);

            return PartialView("~/Views/UserMessage/messages.cshtml", userMessagesViewModel);
        }
    }
}
